package com.tanhua.server.controller;

import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/smallVideos")
public class VideoController {


    @Autowired
    private VideoService videoService;

//    1、请求方式 POST
//    2、请求路径 /smallVideos
//    3、参数 token  和两个文件  videoThumbnail  videoFile
//    4、返回结果 无

    @PostMapping(name = "上传小视频")
    public ResponseEntity uploadVideo(MultipartFile videoThumbnail,MultipartFile videoFile ) throws Exception{
        return videoService.uploadVideo(videoThumbnail,videoFile);
    }

    //    1、请求方式 get
//    2、请求路径 /smallVideos
//    3、参数 token  和两个参数 page  pagesize
//    4、返回结果 PageResult

    @GetMapping(name = "分页查询小视频列表")
    public ResponseEntity queryVideoList(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer pagesize ) throws Exception{
        PageResult pageResult = videoService.queryVideoList(page, pagesize);

        return ResponseEntity.ok(pageResult);
    }


    //    1、请求方式 post
//    2、请求路径 /smallVideos/:uid/userFocus
//    3、参数 token  一个路径参数 uid
//    4、返回结果

    @PostMapping(value = "/{uid}/userFocus",name = "关注视频博主")
    public ResponseEntity userFocus(@PathVariable("uid") Long focusUserId) throws Exception{
        return videoService.userFocus(focusUserId);
    }

    //    1、请求方式 post
//    2、请求路径 /smallVideos/:uid/userUnFocus
//    3、参数 token  一个路径参数 uid
//    4、返回结果

    @PostMapping(value = "/{uid}/userUnFocus",name = "取消关注视频博主")
    public ResponseEntity userUnFocus(@PathVariable("uid") Long focusUserId) throws Exception{
        return videoService.userUnFocus(focusUserId);
    }

}
